package com.dnjn.happiness.system.api.model;

import com.dnjn.happiness.system.api.domain.SysDept;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author happy
 */

public class TeamTreeSelectVO implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    private String deptName;

    private String avatar;

    private String sex;

    private Long deptId;

    private List<UserNode> users;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TeamTreeSelectVO> children;



    public static class UserNode implements Serializable {
        private Long userId;
        private String userName;
        private String nickName;
        private String avatar;
        private String sex;

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getNickName() {
            return nickName;
        }

        public void setNickName(String nickName) {
            this.nickName = nickName;
        }

        public String getAvatar() {
            return avatar;
        }

        public void setAvatar(String avatar) {
            this.avatar = avatar;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }
    }

    public TeamTreeSelectVO() {

    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Long getDeptId() {
        return deptId;
    }

    public void setDeptId(Long deptId) {
        this.deptId = deptId;
    }

    public List<UserNode> getUsers() {
        return users;
    }

    public void setUsers(List<UserNode> users) {
        this.users = users;
    }

    public List<TeamTreeSelectVO> getChildren() {
        return children;
    }

    public void setChildren(List<TeamTreeSelectVO> children) {
        this.children = children;
    }

    public TeamTreeSelectVO(SysDept dept) {
        this.id = dept.getLeaderId();
        this.label = dept.getLeaderName();
        this.deptName = dept.getDeptName();
        this.deptId = dept.getDeptId();
        this.avatar = dept.getAvatar();
        this.sex = dept.getSex();
        this.children = dept.getChildren().stream().map(TeamTreeSelectVO::new).collect(Collectors.toList());
        List<UserNode> userNodeList = new ArrayList<>(dept.getUsers().size());
        dept.getUsers().forEach(user -> {
//            if (!user.getUserId().equals(dept.getLeaderId())) {
                UserNode userNode = new UserNode();
                BeanUtils.copyProperties(user, userNode);
                userNodeList.add(userNode);
//            }
        });
        this.users = userNodeList;
    }


}
